/*****************************************************************************/
/*             Perot Systems Framework                                       */
/*****************************************************************************/
/*     Copyright (C) 2004, Perot Systems Corporation. All right reserved.    */
/*****************************************************************************/
/* Developer: Dmitry Frenkel (dima.frenkel@ps.net)                           */
/* Started:  08/02/2004                                                      */
/*****************************************************************************/
/* Modifications                                                             */
/* Date       |  Author          | Description                               */
/*------------+------------------+-------------------------------------------*/
/*            |                  |                                           */
/******************************************************************************/
SET NOCOUNT OFF
SET ANSI_NULLS ON
SET ANSI_PADDING ON
SET ANSI_WARNINGS ON
SET ARITHABORT ON
SET CONCAT_NULL_YIELDS_NULL ON
SET QUOTED_IDENTIFIER ON
SET NUMERIC_ROUNDABORT OFF
GO

PRINT 'Creating ApplicationLog table...'
GO
IF OBJECT_ID( 'ApplicationLog' ) IS NULL
BEGIN
	CREATE TABLE [DBO].[ApplicationLog] ( 
		[OID] bigint identity(1,1)  NOT NULL,
		[timestamp] rowversion,
		[ApplicationName] VARCHAR(128) NOT NULL,
		[ApplicationVersion] VARCHAR(32) NOT NULL,
		[Host] VARCHAR(64) NOT NULL,
		[StartupParameters] VARCHAR(128) NOT NULL,
		[StartTime] datetime NOT NULL,
		[FinishTime] datetime NULL,
		CONSTRAINT PK_ApplicationLog PRIMARY KEY ([OID]) 
	) 
END
GO

PRINT 'ApplicationLog table has been created'
GO

PRINT 'Creating ApplicationContexts table...'
GO
IF OBJECT_ID( 'ApplicationLog' ) IS NOT NULL AND OBJECT_ID( 'ApplicationContexts' ) IS NULL
BEGIN
	CREATE TABLE [DBO].[ApplicationContexts] ( 
		[OID] bigint identity(1,1)  NOT NULL,
		[timestamp] rowversion,
		[ApplicationID] bigint NOT NULL 
			CONSTRAINT [FK_ApplicationContexts_ApplicationLog]
			FOREIGN KEY ([ApplicationID]) REFERENCES [DBO].[ApplicationLog]( [OID] ),
		[Key] VARCHAR(64),
		[Value] VARCHAR(128),
		CONSTRAINT [PK_ApplicationContexts] PRIMARY KEY ([OID]) ,
		CONSTRAINT [UIX_ApplicationContexts] UNIQUE ([ApplicationID], [Key])
	) 
END
GO

PRINT 'ApplicationContexts table has been created'
GO
